package stc.skymobi.bean.json.meta;

import org.apache.commons.collections.Transformer;
import stc.skymobi.bean.json.annotation.JSONMessage;
import stc.skymobi.bean.util.meta.BeanMetainfoUtils;
import stc.skymobi.bean.util.meta.Int2TypeMetainfo;

import java.util.Collection;

public class JSONCodecUtils {

    private static final Transformer CLS2INT = new Transformer() {

        public Object transform(Object input) {
            Class<?> cls = (Class<?>) input;
            JSONMessage attr = cls.getAnnotation(JSONMessage.class);
            return null != attr ? attr.messageCode() : null;
        }
    };

    static public Int2TypeMetainfo createTopmostTypeMetainfo(Collection<String> packages) {
        return BeanMetainfoUtils.createTypeMetainfo(packages, CLS2INT);
    }
}
